<?php

class GalleryImage
{
    public $artist_first_name;
    public $artist_last_name;
    public $filename;
}

class Gallery extends GalleryImage
{
  public $title;
  public $images;
}


$dir = "./images/thumbnails";
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
        
        $imagearray = array();
        
        while (($file = readdir($dh)) !== false) {
            if($file!="." && $file!="..") {
           	  //echo "$file<br/>";
              if (strpos($file, '.JPG') !== false || strpos($file, '.jpg') !== false) {
                $p1 = new GalleryImage();
    		        $p1->artist_first_name = 'Stephen';
    		        $p1->artist_last_name = 'Price';
		            $p1->filename = $file;  
              
                array_push($imagearray, $p1);
              }
	          }
        }
        
        $m = new Gallery();
        $m->artist_first_name = 'Manager';
        $m->artist_last_name = 'Dude';
        $m->filename = '3098201112_68a301c0a3.jpg'; 
        $m->title = 'Artist Anonymous Gallery';
        $m->images = $imagearray;
       
        echo json_encode($m);  
        
        closedir($dh);
    }
}
?>
